package vn.keho.module.dompeto.model;

import com.google.gson.annotations.SerializedName;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

import vn.keho.define.convert.StringUtil;

/**
 * Created by KeHo on 2/3/15.
 */
public class ChannelModel {
    @SerializedName("channelid")
    private String channelid;
    @SerializedName("slotid")
    private int slotid;
    @SerializedName("channeltitle")
    private String channeltitle;
    @SerializedName("imageurl")
    private String imageurl;

    public ChannelModel(String channelid, int slotid) {
        this.channelid = channelid;
        this.slotid = slotid;
    }

    public ChannelModel(String channelid, String title, String image, int slotid) {
        this.channelid = channelid;
        this.slotid = slotid;
        this.channeltitle = title;
        this.imageurl = image;
    }

    public ChannelModel(JSONObject jsonObject) {
        try {
            this.channelid = jsonObject.getString("channelid");
            this.slotid = jsonObject.getInt("slotid");
            if(jsonObject.has("channeltitle")) {
                this.channeltitle = jsonObject.getString("channeltitle");
                this.imageurl = jsonObject.getString("imageurl");
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public JSONObject toJSON() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("channelid", channelid);
            jsonObject.put("slotid", slotid);
            if(!StringUtil.isBlank(channeltitle)) {
                jsonObject.put("channeltitle", channeltitle);
            }
            if(!StringUtil.isBlank(imageurl)) {
                jsonObject.put("imageurl", imageurl);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    public int getSlotid() {
        return slotid;
    }

    public void setSlotid(int slotid) {
        this.slotid = slotid;
    }

    public String getChannelid() {
        return channelid;
    }

    public void setChannelid(String channelid) {
        this.channelid = channelid;
    }

    public String getChanneltitle() {
        return channeltitle;
    }

    public void setChanneltitle(String channeltitle) {
        this.channeltitle = channeltitle;
    }

    public String getImageurl() {
        return imageurl;
    }

    public void setImageurl(String imageurl) {
        this.imageurl = imageurl;
    }
}
